home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 026-050 / scopedisk46 / flip / ud.asm < prev   
Assembly Source File  |  1995-03-18  |  10KB  |  412 lines

  1. ;registers used as follows:
  2. ;    a2    -    address of old viewport struct
  3. ;    a3    -    address of new viewport struct
  4. ;    a4    -    address of our first bitplane
  5. ;    a5    -    address of our second bitplane
  6.  
  7. ;    d2    -    number of screen flips before exit
  8. ;    d3    -    width of viewport
  9. ;    d4    -    height of viewport
  10. ;    d5    -    depth of viewport
  11. ;    d6    -    bitplane size in bytes (w*h/8)
  12. ;    d7    -    count of #bits that have been rotated
  13. ;*************************************************************
  14.     include "flip.h"
  15.     include "flip.macros"
  16.  
  17.     xdef    ud
  18. ;*************************************************************************
  19.     xref    execbase
  20.     xref    dosbase
  21.     xref    gfxbase
  22.     xref    intbase
  23.     xref    totalpause
  24.     amiref    Delay
  25.     amiref    AllocMem
  26.     amiref    FreeMem
  27.     amiref    InitView
  28.     amiref    InitVPort
  29.     amiref    InitBitMap
  30.     amiref    AllocRaster
  31.     amiref    MakeVPort
  32.     amiref    MrgCop
  33.     amiref    BltClear
  34.     amiref    LoadView
  35.     amiref    FreeRaster
  36.     amiref    FreeVPortCopLists
  37.     amiref    FreeCprList
  38.     amiref    DisplayAlert
  39.     amiref    Forbid
  40.     amiref    Permit
  41. ;*************************************************************************
  42. ;        Macros Start Here
  43. ;*************************************************************************
  44. freeras    macro        ;*plane
  45.     zero    d0
  46.     zero    d1
  47.     move.l    \1,a0        ;free the mem for each bitplane
  48.     move.w    d3,d0        ;feed function the width and height
  49.     move.w    d4,d1        ;and pointer to the plane mem
  50.     gfxlib    FreeRaster
  51.     endm
  52.  
  53. allrast    macro        ;*plane
  54.     zero    d0
  55.     zero    d1
  56.     move.w    d3,d0
  57.     move.w    d4,d1
  58.     gfxlib    AllocRaster    ;allocate the mem for each bitplane
  59.     move.l    d0,\1        ;feed function the width,height
  60.     move.l    d0,(a3)+    ;and pointer to plane mem
  61.     tst.l    d0
  62.     beq    cleanupx    ;branch to DisplayAlert if false
  63.     endm
  64.  
  65. flip    macro        ;*fromplane,*toplane
  66.     pushreg    d6        ;d6 contains the rassize, i.e.,
  67.     zero    d0        ;the # of bytes per bitplane
  68.     zero    d1
  69.     zero    d7
  70.     move.b    #7,d7        ;the rotate bit counter, we'll be working
  71.     move.l    \1,a0        ;with bytes, therefore, 8 bits,count 0 to 7
  72.     adda    d6,a0        ;start at last byte of old bitplane
  73.     move.l    \2,a1
  74. 1$
  75.     tst.l    d6        ;see if we've done all the bytes
  76.     dbeq    d6,2$        ;if we have, then exit the macro
  77.     bra    4$
  78. 2$
  79.     move.b    -(a0),d0    ;decrement, then move the old bitplane
  80.     pushreg    d7        ;byte to d0, save the bit count for later
  81. 3$
  82.     roxr.b    #1,d0        ;rotate the bits at d0 into d1
  83.     roxl.b    #1,d1
  84.     tst.b    d7        ;after each bit rotation check the count
  85.     dbeq    d7,3$        ;to see if we're done with this byte
  86.     move.b    d1,(a1)+    ;if we are, then move the flipped byte
  87.     pullreg    d7        ;to the new bitplane and get back the count
  88.     bra    1$        ;then go back to get next byte
  89. 4$
  90.     pullreg    d6        ;get back the raster size
  91.     endm
  92.  
  93. ;************************************************************************
  94. ;        Macros End Here
  95. ;*************************************************************************
  96. ud
  97.     pushreg    d2-d6/a2-a5
  98.     move.b    #0,check    ;test later to see if view ever opened
  99.                 ;at start we'll assume it did not
  100.     move.l    gfxbase,a0
  101.     move.l    gb_ActiView(a0),oldview        ;get the active view
  102.  
  103.     move.l    intbase,a0
  104.     move.l    ib_ActiveScreen(a0),a1        ;get the active screen
  105.  
  106.     adda    #sc_ViewPort,a1            ;move to screen's viewport
  107.     move.l    a1,a2            ;remember vport struct is inside screen
  108.  
  109.     zero    d5
  110.     move.l    vp_RasInfo(a2),a1    ;find old rasinfo inside vport
  111.     move.l    ri_BitMap(a1),a0    ;find old bitmap inside rasinfo
  112.     move.b    bm_Depth(a0),d5        ;find and save depth inside bitmap
  113.     
  114.     pushreg    d5
  115.     tst.b    d5
  116.     beq    gotoldplanes
  117.     adda    #bm_Planes,a0        ;move to first bitplane addr in bmap
  118.     move.l    (a0)+,d0
  119.     move.l    d0,oldplane1        ;save old bitplane addr
  120.     subq.b    #1,d5
  121.     beq    gotoldplanes        ;do same for each bitplane
  122.     move.l    (a0)+,d0        ;checking depth to see when done
  123.     move.l    d0,oldplane2
  124.     subq.b    #1,d5
  125.     beq    gotoldplanes
  126.     move.l    (a0)+,d0
  127.     move.l    d0,oldplane3
  128.     subq.b    #1,d5
  129.     beq    gotoldplanes
  130.     move.l    (a0)+,d0
  131.     move.l    d0,oldplane4
  132.     subq.b    #1,d5
  133.     beq    gotoldplanes
  134.     move.l    (a0)+,d0
  135.     move.l    d0,oldplane5
  136.     subq.b    #1,d5
  137.     beq    gotoldplanes
  138.     move.l    (a0),d0
  139.     move.l    d0,oldplane6
  140.  
  141. gotoldplanes
  142.     pullreg    d5
  143.  
  144.     zero    d3
  145.     zero    d4
  146.     move.w    vp_DWidth(a2),d3    ;get vport width and height and save
  147.     move.w    vp_DHeight(a2),d4
  148.     zero    d6
  149.     pushreg    d4
  150.     mulu    d3,d4        ;determine raster size from width and height
  151.     lsr.l    #3,d4        ;raster size = width*height/8
  152.     move.l    d4,d6        ;save raster size
  153.     pullreg    d4
  154.  
  155.     getmem    #v_SIZEOF,#MEMF_CLEAR!MEMF_PUBLIC,v
  156.     beq    cleanupx    ;allocate mem for our view struct
  157.  
  158.     getmem    #vp_SIZEOF,#MEMF_CLEAR!MEMF_PUBLIC,a3
  159.     tst.l    d0
  160.     beq    cleanupx    ;allocate mem for our viewport struct
  161.  
  162.     move.l    v,a1
  163.     gfxlib    InitView    ;initialize our view struct
  164.  
  165.     move.l    a3,a0
  166.     gfxlib    InitVPort    ;initialize our viewport struct
  167.  
  168.     move.l    v,a0
  169.     move.l    a3,v_ViewPort(a0)    ;link our viewport to our view
  170.     move.l    oldview,a1
  171.     move.l    v_Modes(a1),v_Modes(a0)    ;set our modes to old modes
  172.  
  173.     getmem    #bm_SIZEOF,#MEMF_CLEAR!MEMF_PUBLIC,b
  174.     beq    cleanupx        ;allocate mem for our bitmap struct
  175.  
  176.     move.l    b,a0
  177.     zero    d0
  178.     move.b    d5,d0
  179.     zero    d1
  180.     move.w    d3,d1
  181.     pushreg    d2
  182.     zero    d2
  183.     move.w    d4,d2
  184.     gfxlib    InitBitMap    ;initialize our bitmap struct
  185.     pullreg    d2
  186.  
  187.     getmem    #ri_SIZEOF,#MEMF_CLEAR!MEMF_PUBLIC,ri
  188.     beq    cleanupx    ;alloc mem for our rasinfo struct
  189.  
  190.     move.l    ri,a0
  191.     move.l    b,a1
  192.     move.l    a1,ri_BitMap(a0)    ;link our bitmap to our rasinfo
  193.     move.l    #0,d0
  194.     move.w    d0,ri_RxOffset(a0)    ;set our rasinfo x,y offsets to zero
  195.     move.w    d0,ri_RyOffset(a0)
  196.     move.l    d0,ri_Next(a0)        ;set pointer to next rasinfo to NULL
  197.  
  198.     move.w    d3,vp_DWidth(a3)    ;set our vport width and height
  199.     move.w    d4,vp_DHeight(a3)    ;to the old values
  200.     move.l    ri,vp_RasInfo(a3)    ;link our rasinfo to our vport
  201.  
  202.     move.l    vp_ColorMap(a2),vp_ColorMap(a3)    ;use the old vport colormap
  203.     move.w    vp_Modes(a2),vp_Modes(a3)    ;and modes
  204.  
  205.     pushreg    d5/a3
  206.     move.l    b,a3
  207.     adda    #bm_Planes,a3    ;move to the first bitplane pointer
  208.                 ;in our bitmap
  209.     allrast    a4        ;allocate space for each bitplane
  210.     subi.b    #1,d5        ;checking depth to see if finished
  211.     beq    gotrasters    ;save the address of each plane in
  212.     allrast    a5        ;register or pointer
  213.     subi.b    #1,d5
  214.     beq    gotrasters
  215.     allrast    plane3
  216.     subi.b    #1,d5
  217.     beq    gotrasters
  218.     allrast    plane4
  219.     subi.b    #1,d5
  220.     beq    gotrasters
  221.     allrast    plane5
  222.     subi.b    #1,d5
  223.     beq    gotrasters
  224.     allrast    plane6
  225.  
  226. gotrasters
  227.     pullreg    d5/a3
  228.  
  229.     move.l    v,a0
  230.     move.l    a3,a1
  231.     gfxlib    MakeVPort    ;got all the info so now make the vport
  232.  
  233.     move.l    v,a1
  234.     gfxlib    MrgCop        ;let copper do its thing
  235.     move.b    #1,check    ;flag to let us know if copper inst. generated
  236.  
  237.     move.l    a4,a1
  238.     move.l    d6,d0
  239.     zero    d1
  240.     gfxlib    BltClear    ;clear each of the bitplanes to zeros
  241.                 ;after checking to see if we got them
  242.     move.l    a5,d0
  243.     beq    bltcleared
  244.     move.l    a5,a1
  245.     move.l    d6,d0
  246.     zero    d1
  247.     gfxlib    BltClear
  248.  
  249.     tst.l    plane3
  250.     beq    bltcleared
  251.     move.l    plane3,a1
  252.     move.l    d6,d0
  253.     zero    d1
  254.     gfxlib    BltClear
  255.  
  256.     tst.l    plane4
  257.     beq    bltcleared
  258.     move.l    plane4,a1
  259.     move.l    d6,d0
  260.     zero    d1
  261.     gfxlib    BltClear
  262.  
  263.     tst.l    plane5
  264.     beq    bltcleared
  265.     move.l    plane5,a1
  266.     move.l    d6,d0
  267.     zero    d1
  268.     gfxlib    BltClear
  269.  
  270.     tst.l    plane6
  271.     beq    bltcleared
  272.     move.l    plane6,a1
  273.     move.l    d6,d0
  274.     zero    d1
  275.     gfxlib    BltClear
  276.  
  277. bltcleared
  278.     pushreg    d5        ;now flip each plane upside down
  279. fone    flip    oldplane1,a4    ;after checking depth to see if done
  280.     subi.b    #1,d5
  281.     beq    readytopause
  282. ftwo    flip    oldplane2,a5
  283.     subi.b    #1,d5
  284.     beq    readytopause
  285. fthree    flip    oldplane3,plane3
  286.     subi.b    #1,d5
  287.     beq    readytopause
  288. ffour    flip    oldplane4,plane4
  289.     subi.b    #1,d5
  290.     beq    readytopause
  291. ffive    flip    oldplane5,plane5
  292.     subi.b    #1,d5
  293.     beq    readytopause
  294. fsix    flip    oldplane6,plane6    
  295.  
  296. readytopause
  297.     pullreg    d5
  298.     execlib    Forbid        ;not sure if this is necessary?
  299.     move.l    v,a1
  300.     gfxlib    LoadView    ;now that we're flipped we can show the view
  301.  
  302.     pause    totalpause
  303.  
  304.     move.l    oldview,a1    ;after pause, bring back old view
  305.     gfxlib    LoadView
  306.     execlib    Permit
  307. cleanupy
  308.     move.l    a4,d0        ;free each of the bitplanes
  309.     beq    freedrast
  310.     freeras    a4
  311.     move.l    a5,d0
  312.     beq    freedrast
  313.     freeras    a5
  314.     tst.l    plane3
  315.     beq    freedrast
  316.     freeras    plane3
  317.     tst.l    plane4
  318.     beq    freedrast
  319.     freeras    plane4
  320.     tst.l    plane5
  321.     beq    freedrast
  322.     freeras    plane5
  323.     tst.l    plane6
  324.     beq    freedrast
  325.     freeras    plane6
  326.  
  327. freedrast
  328.     zero    d0
  329.     move.b    check,d0    ;free the viewport and view mem, only if we
  330.     beq    3$        ;showed the view, not sure why,but get free
  331.     move.l    a3,a0
  332.     move.l    a0,d0
  333.     beq    7$
  334.     gfxlib    FreeVPortCopLists    ;free system allocated memory
  335.  
  336. 1$    move.l    v,a1
  337.     move.l    a1,d0
  338.     beq    7$
  339.     move.l    v_LOFCprList(a1),a0    ;free more sys allocated mem
  340.     move.l    a0,d0
  341.     beq    7$
  342.     gfxlib    FreeCprList
  343.  
  344. 2$    move.l    v,a1
  345.     move.l    a1,d0
  346.     beq    7$
  347.     zero    d1
  348.     move.w    v_Modes(a1),d1
  349.     andi.w    #4,d1            ;check to see view was interlaced
  350.     beq    3$            ;if it wasn't skip this
  351.     move.l    v_SHFCprList(a1),a0    ;if it was then must free this
  352.     move.l    a0,d0            ;extra copperlist memory
  353.     beq    3$
  354.     gfxlib    FreeCprList
  355.     
  356. 3$    move.l    ri,d1
  357.     beq    4$
  358.     byemem    #ri_SIZEOF,ri
  359.  
  360. 4$    move.l    b,d1
  361.     beq    5$
  362.     byemem    #bm_SIZEOF,b        ;free the bitmap mem
  363.  
  364. 5$    zero    d0
  365.     move.b    check,d0    ;free the viewport and view mem, only if we
  366.     beq    7$        ;showed the view, not sure why,but get free
  367.                 ;twice guru if we try to do this after
  368.     move.l    a3,d1        ;DisplayAlert is called.  Memory is still
  369.     beq    7$        ;lost however. Strange. I can't figure it
  370.     byemem    #vp_SIZEOF,a3    ;out. Only 64 bytes anyway, so who cares.
  371.                 ;I do actually, bugs the hell out of me.
  372.                 ;Is it colormap/table related?
  373. 6$    move.l    v,d1
  374.     beq    7$
  375.     byemem    #v_SIZEOF,v
  376.  
  377. 7$    pullreg    d2-d6/a2-a5
  378.     rts
  379. ;*************************************************************************
  380. cleanupx
  381.     move.l    #RECOVERY_ALERT,d0
  382.     lea    almess,a0
  383.     move.l    #50,d1            ;only shown if any memory allocation
  384.     intlib    DisplayAlert        ;returns false
  385.     bra    cleanupy
  386.  
  387. ;************************************************************************
  388.                 DATA
  389. ;***********************************************************************
  390.         evenpc
  391. oldview        dc.l    0
  392. oldplane1    dc.l    0
  393. oldplane2    dc.l    0
  394. oldplane3    dc.l    0
  395. oldplane4    dc.l    0
  396. oldplane5    dc.l    0
  397. oldplane6    dc.l    0
  398. v        dc.l    0
  399. b        dc.l    0
  400. ri        dc.l    0
  401. plane3        dc.l    0
  402. plane4        dc.l    0
  403. plane5        dc.l    0
  404. plane6        dc.l    0
  405. check        dc.b    0
  406.         evenpc
  407. almess
  408.         dc.b    $00,$ba,$14,'Could Not Allocate Enough Memory',0,1
  409.         dc.b    $00,$b6,$22,'Press Either Mouse Button to Exit',0,0
  410.         evenpc
  411.     end
  412.